home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Direct3D / AntiAlias / AntiAlias.fx < prev    next >
Encoding:
Text File  |  2004-09-28  |  5.7 KB  |  222 lines

  1. //--------------------------------------------------------------------------------------
  2. // File: AntiAlias.fx
  3. //
  4. // The effect file for the AntiAlias sample.  
  5. // 
  6. // Copyright (c) Microsoft Corporation. All rights reserved.
  7. //--------------------------------------------------------------------------------------
  8.  
  9.  
  10. //--------------------------------------------------------------------------------------
  11. // Global variables
  12. //--------------------------------------------------------------------------------------
  13. float4x4 g_mWorldViewProjection;    // World * View * Projection matrix
  14.  
  15. texture g_tDiffuse;
  16.  
  17. sampler PointSampler =
  18. sampler_state
  19. {
  20.     Texture = <g_tDiffuse>;
  21.     MinFilter = Point;
  22.     MagFilter = Point;
  23. };
  24.  
  25. sampler LinearSampler =
  26. sampler_state
  27. {
  28.     Texture = <g_tDiffuse>;
  29.     MinFilter = Linear;
  30.     MagFilter = Linear;
  31. };
  32.  
  33. sampler AnisotropicSampler =
  34. sampler_state
  35. {
  36.     Texture = <g_tDiffuse>;
  37.     MinFilter = Anisotropic;
  38.     MagFilter = Anisotropic;
  39.     
  40.     MaxAnisotropy = 4;
  41. };
  42.  
  43. //--------------------------------------------------------------------------------------
  44. // Vertex shader
  45. //--------------------------------------------------------------------------------------
  46. struct VS_OUTPUT
  47. {
  48.     float4 Position : POSITION;
  49.     float4 Diffuse : COLOR0;
  50.     float2 TexCoords : TEXCOORD0;
  51. };
  52.  
  53. VS_OUTPUT ColorVS( float3 Position : POSITION,
  54.                    float4 Diffuse : COLOR0 )
  55. {
  56.     VS_OUTPUT Output;
  57.     
  58.     Output.Position = mul( float4(Position, 1), g_mWorldViewProjection );
  59.     Output.Diffuse = Diffuse;
  60.     Output.TexCoords = 0;
  61.     
  62.     return Output;
  63. }
  64.  
  65. VS_OUTPUT TextureVS( float3 Position : POSITION,
  66.                      float2 TexCoords : TEXCOORD0 )
  67. {
  68.     VS_OUTPUT Output;
  69.     
  70.     Output.Position = mul( float4(Position, 1), g_mWorldViewProjection );
  71.     Output.Diffuse = 0;
  72.     Output.TexCoords = TexCoords;
  73.     
  74.     return Output;
  75. }
  76.  
  77.  
  78. //--------------------------------------------------------------------------------------
  79. // Color fill
  80. //--------------------------------------------------------------------------------------
  81. float4 ColorPS( float4 vDiffuse : COLOR0 ) : COLOR0
  82. {
  83.     return vDiffuse;
  84. }
  85.  
  86.  
  87. technique Color
  88. {
  89.     pass P0
  90.     {
  91.         CullMode = NONE;
  92.         
  93.         VertexShader = compile vs_1_1 ColorVS();
  94.         PixelShader = compile ps_1_1 ColorPS();          
  95.     }
  96. }
  97.  
  98.  
  99. //--------------------------------------------------------------------------------------
  100. // Texture - Point sampled
  101. //--------------------------------------------------------------------------------------
  102. float4 TexturePointPS( float4 TexCoord : TEXCOORD0 ) : COLOR0
  103. {
  104.     return tex2D( PointSampler, TexCoord );
  105. }
  106.  
  107.  
  108. technique TexturePoint
  109. {
  110.     pass P0
  111.     {
  112.         CullMode = NONE;
  113.         
  114.         VertexShader = compile vs_1_1 TextureVS();
  115.         PixelShader = compile ps_1_1 TexturePointPS();          
  116.     }
  117. }
  118.  
  119.  
  120. //--------------------------------------------------------------------------------------
  121. // Texture - Point sampled (centroid)
  122. //--------------------------------------------------------------------------------------
  123. float4 TexturePointCentroidPS( float4 TexCoord : TEXCOORD0_centroid ) : COLOR0
  124. {
  125.     return tex2D( PointSampler, TexCoord );
  126. }
  127.  
  128.  
  129. technique TexturePointCentroid
  130. {
  131.     pass P0
  132.     {
  133.         CullMode = NONE;
  134.         
  135.         VertexShader = compile vs_2_0 TextureVS();
  136.         PixelShader = compile ps_2_0 TexturePointCentroidPS();          
  137.     }
  138. }
  139.  
  140.  
  141. //--------------------------------------------------------------------------------------
  142. // Texture - Linear sampled
  143. //--------------------------------------------------------------------------------------
  144. float4 TextureLinearPS( float4 TexCoord : TEXCOORD0 ) : COLOR0
  145. {
  146.     return tex2D( LinearSampler, TexCoord );
  147. }
  148.  
  149.  
  150. technique TextureLinear
  151. {
  152.     pass P0
  153.     {
  154.         CullMode = NONE;
  155.         
  156.         VertexShader = compile vs_1_1 TextureVS();
  157.         PixelShader = compile ps_1_1 TextureLinearPS();          
  158.     }
  159. }
  160.  
  161.  
  162. //--------------------------------------------------------------------------------------
  163. // Texture - Linear sampled (centroid)
  164. //--------------------------------------------------------------------------------------
  165. float4 TextureLinearCentroidPS( float4 TexCoord : TEXCOORD0_centroid ) : COLOR0
  166. {
  167.     return tex2D( LinearSampler, TexCoord );
  168. }
  169.  
  170.  
  171. technique TextureLinearCentroid
  172. {
  173.     pass P0
  174.     {
  175.         CullMode = NONE;
  176.         
  177.         VertexShader = compile vs_2_0 TextureVS();
  178.         PixelShader = compile ps_2_0 TextureLinearCentroidPS();          
  179.     }
  180. }
  181.  
  182.  
  183. //--------------------------------------------------------------------------------------
  184. // Texture - Anisotropic sampled
  185. //--------------------------------------------------------------------------------------
  186. float4 TextureAnisotropicPS( float4 TexCoord : TEXCOORD0 ) : COLOR0
  187. {
  188.     return tex2D( AnisotropicSampler, TexCoord );
  189. }
  190.  
  191.  
  192. technique TextureAnisotropic
  193. {
  194.     pass P0
  195.     {
  196.         CullMode = NONE;
  197.         
  198.         VertexShader = compile vs_1_1 TextureVS();
  199.         PixelShader = compile ps_1_1 TextureAnisotropicPS();          
  200.     }
  201. }
  202.  
  203.  
  204. //--------------------------------------------------------------------------------------
  205. // Texture - Anisotropic sampled (centroid)
  206. //--------------------------------------------------------------------------------------
  207. float4 TextureAnisotropicCentroidPS( float4 TexCoord : TEXCOORD0_centroid ) : COLOR0
  208. {
  209.     return tex2D( AnisotropicSampler, TexCoord );
  210. }
  211.  
  212.  
  213. technique TextureAnisotropicCentroid
  214. {
  215.     pass P0
  216.     {
  217.         CullMode = NONE;
  218.         
  219.         VertexShader = compile vs_2_0 TextureVS();
  220.         PixelShader = compile ps_2_0 TextureAnisotropicCentroidPS();          
  221.     }
  222. }